package com.yiya.service;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiya.bean.Repository;
import com.yiya.bean.SysUser;
import com.yiya.mapper.RepositoryMapper;
import com.yiya.model.RepositoryModel;

@Service("repositoryService")
public class RepositoryService {
	@SuppressWarnings("unused")
	private final static Logger log = Logger.getLogger(RepositoryService.class);

	@Autowired
	private RepositoryMapper repositoryMapper;

	public List<Repository> queryByList(RepositoryModel bean) {
		Integer rowCount = queryByCount(bean);
		bean.getPager().setRowCount(rowCount);
		List<Repository> repositories = repositoryMapper.selectByModel(bean);
		return repositories;
	}
	
	public int queryByCount(RepositoryModel bean){
		return repositoryMapper.countByModel(bean);
	}
	
	public int add(Repository repository){
		return repositoryMapper.insert(repository);
	}
	
	public int Update(Repository repository){
		return repositoryMapper.updateByPrimaryKeySelective(repository);
	}
	
	public Repository queryById(Integer id){
		return repositoryMapper.selectByPrimaryKey(id);
	}
	
	public void delete(Integer[] ids,SysUser user){
		Date nowTime = new Date();
		for(Integer id:ids){
			Repository repository = repositoryMapper.selectByPrimaryKey(id);
			repository.setUpdateBy(user.getId());
			repository.setUpdateTime(nowTime);
			repository.setDelFlag(1);
			repositoryMapper.updateByPrimaryKeySelective(repository);
		}
	}
	
	public List<Repository> queryAllList(RepositoryModel bean){
		return repositoryMapper.queryAllList(bean);
	}
}
